import {
  Module,
  NestModule,
  MiddlewareConsumer,
  RequestMethod,
} from '@nestjs/common';
import { SmsService } from './sms.service';
import { SmsController } from './sms.controller';

// 中间件
import sendSmsApiMiddleware from './middlewares/sendSms.middleware';
import checkCaptchaByIDMiddleware from './middlewares/checkCaptchaByID.middleware';

@Module({
  controllers: [SmsController],
  providers: [SmsService],
})
// export class SmsModule {}
export class SmsModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    // 1、发送验证码接口
    consumer.apply(sendSmsApiMiddleware.CheckParamIsEmptyMiddleware).forRoutes({
      method: RequestMethod.POST,
      path: '/sms/sendSms',
    });

    // 2、校验验证码接口
    consumer
      .apply(checkCaptchaByIDMiddleware.CheckParamIsEmptyMiddleware)
      .forRoutes({
        method: RequestMethod.POST,
        path: '/sms/checkCaptchaByID',
      });
  }
}
